import { useEffect, useMemo, useState } from "react"
import { BASE_PATH,API } from '@/config'
import requewt from '@/utils/requewt'


export const useCar = (category) => {
    const width = global.innerWidth
    const [sprites, setSprites] = useState([])
    const [initMenus, setInitMenus] = useState({})
    
    const cars = useMemo(() => {
        const data = {
            '1': {
                car: {
                    image: `${BASE_PATH}/img/game/UNI-K.png`,
                    width: 260,
                    height: 115,
                    x: width*0.5-116,
                    y: 34,
                    zIndex: 10
                },

                menus: [
                    {
                        label: '贴膜',
                        type: 'tiemo',
                        value: 0,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/uni-k-1-v1.png`,
                                width: 236.4,
                                height: 91,
                                x: width*0.5 -115.8,
                                y: 34
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-1-v2.png`,
                                width: 236.4,
                                height: 91,
                                x: width*0.5 -115.8,
                                y: 34
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-1-v3.png`,
                                width: 236.4,
                                height: 91,
                                x: width*0.5 -115.8,
                                y: 34
                            },
        
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-1-1.png`,
                                style: {
                                    width: '40px',
                                    height: '40px',
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-1-2.png`,
                                style: {
                                    width: '40px',
                                    height: '40px',
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-1-3.png`,
                                style: {
                                    width: '40px',
                                    height: '40px',
                                }
                            },
                        ]
                    },
                    {
                        label: '前保险杠',
                        type: 'weiyi',
                        value: 0,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/uni-k-2-v1.png`,
                                width: 56,
                                height: 10.66,
                                x: width*0.5 -114,
                                y: 110,
                                // zIndex: 8
                                
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-2-v2.png`,
                                width: 56,
                                height: 10.66,
                                x: width*0.5 -114,
                                y: 110,
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-2-v3.png`,
                                width: 56,
                                height: 10.66,
                                x: width*0.5 -114,
                                y: 110,
                                // zIndex: 8
                            },
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-2-1.png`,
                                style: {
                                    width: '80%'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-2-2.png`,
                                style: {
                                    width: '80%'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-2-3.png`,
                                value: `${BASE_PATH}/img/game/car-component-6-v.png`,
                                style: {
                                    width: '80%'
                                }
                            },
                        ]
                    },
                    {
                        label: '轮毂',
                        type: 'lungu',
                        value: 0,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/uni-k-3-v1.png`,
                                width: 122,
                                height: 44,
                                x: width*0.5-10,
                                y: 92
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-3-v2.jpg`,
                                width: 122,
                                height: 44,
                                x: width*0.5-10,
                                y: 92
                            }  
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-3-1.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '52px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-3-2.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '52px'
                                }
                            },
                        ]
                    },
                    {
                        label: '侧镜',
                        type: 'cejing',
                        value: 0,
                        uNum: 200,
                        caseNum: 1,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/uni-k-4-v1.png`,
                                width: 104,
                                height: 12,
                                x: width*0.5-60,
                                y: 51
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-4-v2.png`,
                                width: 104,
                                height: 12,
                                x: width*0.5-60,
                                y: 51
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-4-v3.png`,
                                width: 104,
                                height: 12,
                                x: width*0.5-60,
                                y: 51
                            },
                            
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-4-1.png`,
                                style: {
                                    width: '52px',
                                    height: '31px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-4-2.png`,
                                style: {
                                    width: '52px',
                                    height: '31px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-4-3.png`,
                                style: {
                                    width: '50px',
                                    height: '31px'
                                }
                            },
                        ]
                    },
                    {
                        label: '车灯',
                        type: 'chedeng',
                        value: 0,
                        uNum: 1200,
                        caseNum: 5,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/uni-k-5-v1.png`,
                                width: 47,
                                height: 28.33,
                                x: width*0.5-62,
                                y: 60
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-5-v2.png`,
                                width: 47,
                                height: 28.33,
                                x: width*0.5-62,
                                y: 60
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-5-v3.png`,
                                width: 47,
                                height: 28.33,
                                x: width*0.5-62,
                                y: 60
                            },
                        ],
                        items: [
                                    {
                                        imgUrl: `${BASE_PATH}/img/game/uni-k-5-1.png`,
                                        value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                        style: {
                                            width: '71px',
                                            height: '28px'
                                        }
                                    },
                                    {
                                        imgUrl: `${BASE_PATH}/img/game/uni-k-5-2.png`,
                                        value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                        style: {
                                            width: '71px',
                                            height: '28px'
                                        }
                                    },
                                    {
                                        imgUrl: `${BASE_PATH}/img/game/uni-k-5-3.png`,
                                        value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                        style: {
                                            width: '71px',
                                            height: '28px'
                                        }
                                    },
                                ]
                    },
                    {
                        label: '车贴',
                        type: 'chetie',
                        value: 0,
                        uNum: 2000,
                        caseNum: 8,
                        children: [
                            
                            {
                                image: `${BASE_PATH}/img/game/uni-k-6-v1.png`,
                                width: 236.4,
                                height: 91,
                                x: width*0.5 -115.8,
                                y: 34
                            },
                            {
                                image: `${BASE_PATH}/img/game/uni-k-6-v2.png`,
                                width: 236.4,
                                height: 91,
                                x: width*0.5 -115.8,
                                y: 34
                            }
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-6-1.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '40px',
                                    height: '40px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/uni-k-6-2.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '40px',
                                    height: '40px'
                                }
                            }
                        ]
                    }
                ]
            },
            '2': {
                car: {
                    image: `${BASE_PATH}/img/game/base_car.png`,
                    width: 240,
                    height: 101,
                    x: width*0.5-120,
                    y: 46,
                    zIndex: 10
                },
                menus: [
                    {
                        label: '贴膜',
                        type: 'tiemo',
                        value: 0,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                width: 240,
                                height: 87,
                                x: width*0.5 -120,
                                y: 46
                            },
                            {
                                image: `${BASE_PATH}/img/game/pink_black_bg.png`,
                                width: 240,
                                height: 87,
                                x: width*0.5 -120,
                                y: 46
                            },
                            {
                                image: `${BASE_PATH}/img/game/yello_green_bg.png`,
                                width: 240,
                                height: 87,
                                x: width*0.5 -120,
                                y: 46
                            },
        
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/game_icon_1.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '40px',
                                    height: '40px',
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/game_icon_2.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '40px',
                                    height: '40px',
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/game_icon_3.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '40px',
                                    height: '40px',
                                }
                            },
                        ]
                    },
                    {
                        label: '尾翼',
                        type: 'weiyi',
                        value: 0,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/car-component-4-v.png`,
                                width: 48,
                                height: 16,
                                x: width*0.5 +76,
                                y: 58,
                                zIndex: 8
                                
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-5.png`,
                                width: 48,
                                height: 16,
                                x: width*0.5 +76,
                                y: 58,
                                zIndex: 8
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-6.png`,
                                width: 48,
                                height: 16,
                                x: width*0.5 +76,
                                y: 58,
                                zIndex: 8
                            },
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-4.png`,
                                value: `${BASE_PATH}/img/game/car-component-4-v.png`,
                                style: {
                                    width: '80%'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-5.png`,
                                value: `${BASE_PATH}/img/game/car-component-5-v.png`,
                                style: {
                                    width: '80%'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-4.png`,
                                value: `${BASE_PATH}/img/game/car-component-6-v.png`,
                                style: {
                                    width: '80%'
                                }
                            },
                        ]
                    },
                    {
                        label: '轮毂',
                        type: 'lungu',
                        value: 0,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/car-component-20.png`,
                                width: 108,
                                height: 44,
                                x: width*0.5 + 5,
                                y: 100
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-21.png`,
                                width: 108,
                                height: 44,
                                x: width*0.5 + 5,
                                y: 100
                            }  
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-8.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '52px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-7.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '52px'
                                }
                            }
                            
                        ]
                    },
                    {
                        label: '侧镜',
                        type: 'cejing',
                        value: 0,
                        uNum: 200,
                        caseNum: 1,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/car-component-22.png`,
                                width: 123,
                                height: 15,
                                x: width*0.5-62,
                                y: 63
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-23.png`,
                                width: 123,
                                height: 15,
                                x: width*0.5-62,
                                y: 63
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-24.png`,
                                width: 123,
                                height: 15,
                                x: width*0.5-62,
                                y: 63
                            },
                            
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-9.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '52px',
                                    height: '31px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-10.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '52px',
                                    height: '31px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-11.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '50px',
                                    height: '31px'
                                }
                            },
                        ]
                    },
                    {
                        label: '车灯',
                        type: 'chedeng',
                        value: 0,
                        uNum: 1200,
                        caseNum: 5,
                        children: [
                            {
                                image: `${BASE_PATH}/img/game/car-component-25.png`,
                                width: 111,
                                height: 20,
                                x: width*0.5-114,
                                y: 81
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-26.png`,
                                width: 111,
                                height: 20,
                                x: width*0.5-114,
                                y: 81
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-27.png`,
                                width: 111,
                                height: 20,
                                x: width*0.5-114,
                                y: 81
                            },
                        ],
                        items: [
                                    {
                                        imgUrl: `${BASE_PATH}/img/game/car-component-12.png`,
                                        value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                        style: {
                                            width: '71px',
                                            height: '28px'
                                        }
                                    },
                                    {
                                        imgUrl: `${BASE_PATH}/img/game/car-component-13.png`,
                                        value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                        style: {
                                            width: '71px',
                                            height: '28px'
                                        }
                                    },
                                    {
                                        imgUrl: `${BASE_PATH}/img/game/car-component-14.png`,
                                        value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                        style: {
                                            width: '71px',
                                            height: '28px'
                                        }
                                    },
                                ]
                    },
                    {
                        label: '车贴',
                        type: 'chetie',
                        value: 0,
                        uNum: 2000,
                        caseNum: 8,
                        children: [
                            
                            {
                                image: `${BASE_PATH}/img/game/car-component-29.png`,
                                width: 240,
                                height: 87,
                                x: width*0.5 -120,
                                y: 46
                            },
                            {
                                image: `${BASE_PATH}/img/game/car-component-28.png`,
                                width: 240,
                                height: 87,
                                x: width*0.5 -120,
                                y: 46
                            }
                        ],
                        items: [
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-16.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '40px',
                                    height: '40px'
                                }
                            },
                            {
                                imgUrl: `${BASE_PATH}/img/game/car-component-17.png`,
                                value: `${BASE_PATH}/img/game/blue_pink_bg.png`,
                                style: {
                                    width: '40px',
                                    height: '40px'
                                }
                            }
                        ]
                    }
                ]
            }
        }
        const tempMenus = data[category].menus
        Object.keys(initMenus || {}).forEach((key) => {
                const index = tempMenus.findIndex(i => i.type === key)
                tempMenus.splice(index, 1, {...tempMenus[index],value: initMenus[key]})
            })
        return data
    }, [width,initMenus,category])
    // const [menus, setMenus] = useState()
    const menus = useMemo(() => {
        return cars[category].menus
    }, [cars,category])
    const car = useMemo(() => {
        return cars[category].car
    }, [category])
    useEffect(() => {
        requewt(API.user.fitting).then(({data}) => {
            setInitMenus(data)
        })
    },[])
    return {
        menus,
        car,
        sprites, setSprites
    }
}